This file and its intellectual contents are considered property of the creator and are to be treated as such with respect to use in other applications. Any use of this software for any purpose whatsoever must have explicit permission from the author of the file. This code is part of an ongoing development process for future possible products, and so is considered private property.
Do not use without permission. Author: Scott C. Ziegler <Aslan@Narnia.net>
*/
import java.awt.*;
import java.io.*;
import javax.swing.*;
import java.util.*;
public class Mentat {
public static final String LIST_COMMANDS = "?, about, addEntry, addEntryFromFile, removeEntry, lookupEntry, listEntries, changeName, saveArchive, loadArchive, Quit";
// Members
boolean interactionMode;
boolean touched;
InteractionFrame mentatFrame;
Archive archie;
FileInputStream fis;
FileOutputStream fos;
// Constructors
public Mentat() {
mentatFrame = new InteractionFrame();
archie = new Archive();
interactionMode = true;
}
// Selectors
public Archive getArchie() { return archie; }
public boolean getInteractionMode() { return interactionMode; }
// Mutators
public void setArchie(Archive newArchie) { newArchie = new Archive(); }
public void setInteractionMode(boolean mode) { interactionMode = mode; }
// Methods
public void mainline() {
String selector;
while(true) {
selector = mentatFrame.getLine();
if (selector.compareTo("") == 0) {
mentatFrame.printEndLine("Enter a command, Moron!");
}
else if (selector.compareTo("help") == 0) {
mentatFrame.printLine("Mentat Thufir Howat, at your service.");
mentatFrame.print("Available commands: ");
mentatFrame.printEndLine(LIST_COMMANDS);
}
else if (selector.compareTo("Commands?") == 0 || selector.compareTo("?") == 0) {
mentatFrame.printEndLine(LIST_COMMANDS);
}
else if (selector.compareTo("about") == 0) {
about();
}
else if (selector.compareTo("addEntry") == 0) {
addEntry();
}
else if (selector.compareTo("addEntryFromFile") == 0) {
addEntryFromFile();
}
else if (selector.compareTo("removeEntry") == 0) {
removeEntry();
}
else if (selector.compareTo("lookupEntry") == 0) {
lookupEntry();
}
else if (selector.compareTo("listEntries") == 0) {
listEntries();
}
else if (selector.compareTo("changeName") == 0) {
changeName();
}
else if (selector.compareTo("saveArchive") == 0) {
saveArchive();
}
else if (selector.compareTo("loadArchive") == 0) {
mentatFrame.printEndLine("The command \""+ selector +"\" was not recognized!");
}
}
}
public void about() {
mentatFrame.printLine("Mentat for MacHack 2001");
mentatFrame.printLine("written by Scott C. Ziegler, 2000-2001");
mentatFrame.printLine("presented at MacHack 2001 on MacOS X");
mentatFrame.printLine(" This small application was developed during experimentations with the Java programming language and its Java Foundation Classes, including Swing. This is for all those mental notes that always seem to get lost in the cobwebs behind all the deprecated APIs. This app is dedicated to my friends from days of old when magick filled the aire, and to those who have ever felt the age-smoothed edges of a polyhedron as it decided the fate of some hapless character.");
mentatFrame.printEndLine("You never saw this fnord.");
}
public void addEntry() {
String keyString = new String("");
String valueString = new String("");
mentatFrame.printLine("Adding an Entry:");
// key variable acquisition
keyString = getLineLoop("Enter the desired key (i.e. keyword)...",
"That is an invalid key!");
// value variable acquisition
valueString = getLineLoop("Enter the desired value associated with this key...",
"That value is rather silly, don't you think?");
archie.addEntry(keyString, valueString);
mentatFrame.printEndLine("Entry Added.");
touched = true;
// if () { } // check for entry's existence? then report?
}
public void addEntryFromFile() {
String filename = new String("");
String key = new String("");
mentatFrame.printLine("Adding and Entry from file:");
key = getLineLoop("Enter the desired key (i.e. keyword)...",
"That is an invalid key!");
filename = getLineLoop("Enter the filename of the value for the entry.",
"That is an invalid filename!");
try {
FileReader in = new FileReader(filename);
BufferedReader bf = new BufferedReader(in);
archie.addEntry(key, bf.readLine());
mentatFrame.printEndLine("Entry Added.");
touched = true;
}
catch (IOException ioe) {
System.out.println("Error: " + ioe.toString());
}
}
public void removeEntry() {
String key = new String("");
mentatFrame.printLine("Removing an Entry:");
key = getLineLoop("Enter the key of the entry to be deleted:", "Can't destroy nothing, silly!");
// Add are you sure dialog text.
archie.removeEntry(key);
mentatFrame.printEndLine("Entry removed.");
touched = true;
}
public void lookupEntry() {
String key = new String("");
mentatFrame.printLine("Lookup an Entry:");
key = getLineLoop("Enter the key of the entry to be looked up:",